//
//  FriendImpresstionSecCell.m
//  u76ho
//
//  Created by m-air-01 on 15/12/28.
//  Copyright © 2015年 LV. All rights reserved.
//

#import "FriendImpresstionSecCell.h"

@implementation FriendImpresstionSecCell

- (void)awakeFromNib {
    // Initialization code
}
-(void)setDataArr:(NSArray *)dataArr
{
    _dataArr = dataArr;
    
    CGFloat totalW1;
    totalW1 = 0;
    CGFloat width1 = SCREEN_WIDTH-SIZETO6W(15)*2;
    int j1 = 0;
    for (int i = 0; i<dataArr.count; i++) {
        NSString * str = dataArr[i];
        CGFloat w = [str widthOfSize:20]+SIZETO6W(10);
        totalW1 += w+SIZETO6W(10);
        if (totalW1<=width1) {
            UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(SIZETO6W(15)+totalW1-w-SIZETO6W(10), _lab.bottom+SIZETO6W(15) + j1*(30+SIZETO6H(15)), w, 30);
            [btn setTitle:dataArr[i] forState:UIControlStateNormal];
            [btn setTitleColor:UIColorFromRGB(0x94999f) forState:UIControlStateNormal];
            btn.layer.borderColor = [UIColorFromRGB(0x94999f) CGColor];
            btn.layer.borderWidth = 1.0f;
            btn.layer.masksToBounds = YES;
            btn.layer.cornerRadius = 15;
            btn.tag = i+1;
            [btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:btn];
        }
        else
        {
            j1 = j1+1;

            totalW1 = w+SIZETO6W(10);
            UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(SIZETO6W(15), _lab.bottom+SIZETO6W(15) + j1*(30+SIZETO6H(15)), w, 30);
            [btn setTitle:dataArr[i] forState:UIControlStateNormal];
            [btn setTitleColor:UIColorFromRGB(0x94999f) forState:UIControlStateNormal];
            btn.layer.borderColor = [UIColorFromRGB(0x94999f) CGColor];
            btn.layer.borderWidth = 1.0f;
            btn.layer.masksToBounds = YES;
            btn.layer.cornerRadius = 15;
            btn.tag = i+1;
            [btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:btn];

        }
        
    }
}
-(void)btnAction:(UIButton *)btn
{
    int i = (int)btn.tag;
    if (_block) {
        _block(i);
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
